#!./perl

# ------------------------------------------------------------

# tarfiles.pl, by Jean-Pierre Girard (jpg@corrado.sun.com)
# This allows the development environment to choose what
# page to load depending on the existence of .cdev

# ------------------------------------------------------------

# Bugs and other fixes

# ------------------------------------------------------------

##############################################################################
# main
##############################################################################
$BASEDIR = $ENV{"DOCUMENT_ROOT"};
require 'devinfo.pl';
require 'tools.pl';
$IMAGE_GR_BUL = "<IMG ALIGN=middle src=\"file:///tmp/httpd/.products/DEV/images/bullet_ball_green.gif\">";
$IMAGE_RED_BUL = "<IMG ALIGN=middle src=\"file:///tmp/httpd/.products/DEV/images/bullet_ball_red.gif\">";
if ($ENV{'REQUEST_METHOD'} eq "POST") {
	read(STDIN, $request, $ENV{'CONTENT_LENGTH'});
} elsif ($ENV{'REQUEST_METHOD'} eq "GET" ) {
	$request = $ENV{'QUERY_STRING'};
}

$HomeDir = &GetDevinfo("dir");
#$TARFILE = $HomeDir . "/../cdware.tar";
$ShortDir = $HomeDir;
$ShortDir =~ s?.*/([^/]*)$?\1?;

$~ = HEADER;
write;
$Status=1;
$request =~ s/%(..)/pack("c",hex($1))/ge;
#print "request=$request<br>";
#print "ARGV0=$ARGV[0]<br>";
#if (@ARGV == 0 && $request eq "") {


if ($request ne "") {
	if ($request =~ /^FTPDEV/) {
		#print "in case request=tapedev<br>";
		$Device = $request;
		$Device =~ s/FTPDEV=//;
		$TarFile = $HomeDir;
		$TarFile =~ s?.*/([^/]*)$?\1.tar?;
		#$TarFile = "$BASEDIR/$TarFile";
		$Status = system ("cmdtool csh -c 'cd $BASEDIR;tar cvf $TarFile $ShortDir;rm -f $TarFile.Z;compress $TarFile;echo \" \";echo \"The size of the file to send is (in Kb): \"`du -ks $TarFile.Z`;echo \" \";echo \"READ THIS: Please ftp this file.\";echo \" \";echo \"The ftp site is xm.com (open xm.com).\";echo \"The login name is \'cdware\'. The password is \'jan1995\'.\";echo \"Just copy your file ($TarFile.Z) in the current directory:\";$Device;echo \" \";echo \"Press <Return> to close this window...\";read a'");
		#print "Status=$Status<br>";
	}
	if ($request =~ /^TAPEDEV/) {
		#print "in case request=tapedev<br>";
		$Device = $request;
		$Device =~ s/TAPEDEV=//;
		if (-c $Device) {
			#print "cmdtool /bin/csh \<echo \"test\"";
			$TarFile = $HomeDir;
			$TarFile =~ s?.*/([^/]*)$?\1.tar?;
			#$TarFile = "$BASEDIR/$TarFile";
			$Status = system ("cmdtool csh -c 'cd $BASEDIR;tar cvf $TarFile $ShortDir;rm -f $TarFile.Z;compress $TarFile;echo \"The size of the file to send is (in Kb): \"`du -ks $TarFile.Z`;echo \" \";echo \"Copying file on tape:\";tar cvf $Device $TarFile.Z;echo \" \";echo \"Press <Return> to close this window...\";read a'");
			#print "Status=$Status<br>";
		} else {
			$Status = &PrintErr("NoDevice", $Device);
			$ARGV[0] = "TAPE";
		}
	}
	if ($request =~ /^DISKDEV/) {
		#print "in case request=tapedev<br>";
		$Device = $request;
		$Device =~ s/DISKDEV=//;
		if (-c $Device) {
			#print "cmdtool /bin/csh \<echo \"test\"";
			$TarFile = $HomeDir;
			$TarFile =~ s?.*/([^/]*)$?\1.tar?;
			#$TarFile = "$BASEDIR/$TarFile";
			$Status = system ("cmdtool csh -c 'cd $BASEDIR;tar cvf $TarFile $ShortDir;rm -f $TarFile.Z;compress $TarFile;echo \"The size of the file to send is (in Kb): \"`du -ks $TarFile.Z`;echo \" \";echo \"Copying file on diskette(s):\";echo \"$TarFile.Z\"|cpio -uo -O $Device;echo \" \";echo \"Press <Return> to close this window...\";read a'");
			#print "Status=$Status<br>";
		} else {
			$Status = &PrintErr("NoDevice", $Device);
			$ARGV[0] = "DISKETTE";
		}
	}
}
if ($ARGV[0] ne "") {
	if ($ARGV[0] eq "FTP") {
		print "<hr>Please enter your ftp command name:"
		, "<FORM method=\"post\"  ACTION=\"http://localhost:7999/cgi-bin/tarfiles.pl?\">"
		,"<INPUT TYPE=\"text\" NAME=\"FTPDEV\" VALUE=\""
		,($Device ne ""?$Device:"ftp"), "\" SIZE=\"20\" MAXLENGTH=50>"
		," <input type=\"submit\" VALUE=\"Send\" > </FORM>"
	} elsif ($ARGV[0] eq "TAPE") {
		print "<hr>Please enter your device name:"
		, "<FORM method=\"post\"  ACTION=\"http://localhost:7999/cgi-bin/tarfiles.pl?\">"
		,"<INPUT TYPE=\"text\" NAME=\"TAPEDEV\" VALUE=\""
		,($Device ne ""?$Device:"/dev/rst5"), "\" SIZE=\"20\" MAXLENGTH=50>"
		," <input type=\"submit\" VALUE=\"Copy on tape\" > </FORM>"
	} elsif ($ARGV[0] eq "DISKETTE") {
		print "<hr>Please enter your diskette drive name:"
		, "<FORM method=\"post\"  ACTION=\"http://localhost:7999/cgi-bin/tarfiles.pl?\">"
		,"<INPUT TYPE=\"text\" NAME=\"DISKDEV\" VALUE=\""
		,($Device ne ""?$Device:"/dev/rdiskette"), "\" SIZE=\"20\" MAXLENGTH=50>"
		," <input type=\"submit\" VALUE=\"Copy on diskette\" > </FORM>";
		print "<p><img ALIGN=middle src=\"file:///tmp/httpd/.products/DEV/images/finger.gif\">Before clicking on the button, you need to stop the volume manager:<br><ol><li>Become superuser<br><li>Type the command: <tt>/etc/init.d/volmgt stop</tt><li>Check that the volume manager is stopped by typing the command: <tt>ps -ea|grep vold</tt>. You shouldn't get any return. If vold is still running, one of your applications must be using it and need to be exited.<li>Once the volume manager is stopped, you can insert a diskette in your drive and press the button \"Copy on diskette\".<li>To restart the volume manager, enter the following command: <tt>/etc/init.d/volmgt start</tt>.</ol>";
	}
}
if ($ARGV[0] eq "" && $request eq "") {
	unless (-s $HomeDir . "/_info") {
		&PrintErr("NoExist", "$HomeDir/_info");
	}
	unless (-s $HomeDir . "/index.html") {
		&PrintErr("NoExist", "$HomeDir/index.html");
	}
	print "<h2>Are you sure you are done with your insertion?</h2>";
	print "<ul><H4>$IMAGE_RED_BUL<a href=\"http://localhost:7999/cgi-bin/mainmenu.pl?\">Go back to main menu</a></H4>";
	print "<p>$IMAGE_RED_BULChoose how you will send your insertion to Sun Microsystems:</p><ol>";
	print "<H2>$IMAGE_GR_BUL<a href=\"http://localhost:7999/cgi-bin/tarfiles.pl?FTP\">Using ftp</a></H2>";
	print "<H2>$IMAGE_GR_BUL<a href=\"http://localhost:7999/cgi-bin/tarfiles.pl?TAPE\">Using a tape</a></H2>";
	print "<H2>$IMAGE_GR_BUL<a href=\"http://localhost:7999/cgi-bin/tarfiles.pl?DISKETTE\">Using diskettes</a></H2></ol></ul>";

} elsif ($Status == 0) {
	$~ = FINISHED;
	write;
}


	$~ = FOOTER;
	write;


##############################################################################
# formats
##############################################################################
format HEADER =
Content-type: text/html


<html>
<title>Developer's Kit</title>
<body>
<h1>CDware Developer's Kit</h1>
<h4>Currently working with "@*
$HomeDir
"</h4>
#<ol type=1>
.

format FOOTER =
#</ol>
<p>
<hr>
<p>
You, like these companies, will benefit from the CDware capability of reaching tens of thousands of potential customers with information, links to your web site, or directly with YOUR product!
<p><app class=ImageTape width=596 height=65 img_dir=../../../DEV/logos speed=10 dir=-10
url1=oracle
url2=progress
url3=gupta
url4=informix
url5=lotus
url6=ingres
>
</b>
<h5><p><A HREF=file:///tmp/httpd/.products/CDware/Help/SMICopyright.html>Copyright</A> 1995 Sun Microsystems, Inc., 2550 Garcia Ave., Mtn. View, CA 94043 USA.  All rights reserved.</h5><br></pre>
<a href=file:///tmp/httpd/.products/DEV/credits.html>Credits</a>
</b>
</form>
</body>
</html>
.

format FINISHED =
</ol>
<p>
<h1><app class="ImageLoopItem" ALIGN=middle width=55 height=68 img="file:///tmp/httpd/.products/DEV/images/duke">You're done!</h1>
<p>Please submit your tape or diskette to:<br>
<b>Jason Incorvaia (415-336-1920)<br>
2550 Garcia Ave.<br>
MS-UMTV08<br>
Mountain View, CA 94043-1100<br></b>
<h3>Please send us an Email to let us know that we should expect your insertion: <A href="mailto:cdware@sun.com">cdware@sun.com</A></h3>
"@", "@"
<p><app class="ImageLoopItem" img="file:///tmp/httpd/.products/DEV/images/blinkingAlert" ALIGN=middle pause=0 width=56 height=49 pause = 200>Once you sent us an Email, you can just quit hotjava or use it to browse the web!</p>
<p>
<ul>
<H4><IMG ALIGN=middle src="file:///tmp/httpd/.products/DEV/images/bullet_ball_green.gif"><a href="http://localhost:7999/cgi-bin/mainmenu.pl?">Main menu</a></H4>
<H4><IMG ALIGN=middle src="file:///tmp/httpd/.products/DEV/images/bullet_ball_green.gif"><a href="http://www.sun.com">Sun's home page</a></H4>
</ul>
.

